package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckGroupAndCheckItem;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CheckGroupMapper {
    /**
     * 添加检查组
     *
     * @param checkGroup
     */
    void add(CheckGroup checkGroup);

    /**
     * 分页查询
     *
     * @param queryPageBean
     * @return
     */
    Page<CheckGroup> pageQuery(QueryPageBean queryPageBean);

    /**
     * 根据id查询是否存在套餐
     *
     * @param id
     * @return
     */
    @Select("select s.setmeal_id from t_setmeal_checkgroup s where checkgroup_id=#{id}")
    List<Long> findCheckGroupIdBySetMealId(Long id);

    /**
     * 删除检查组
     *
     * @param id
     */
    @Delete("delete from t_checkgroup where id= #{id}")
    void deletecheckGroup(Long id);

    /**
     * 根据检查组id查询检查项id
     *
     * @param setmealId
     * @return
     */
    @Select("select checkgroup_id from t_setmeal_checkgroup where setmeal_id= #{setmealId}")
    List<Long> findCheckGroupIdsBySetmealId(Long setmealId);

    /**
     * 根据Id查询检查组
     *
     * @param id
     * @return
     */
    @Select("select *from t_checkgroup where id=#{id}")
    List<CheckGroup> findById(Long id);

    /**
     * 查找所有检查组
     *
     * @return
     */
    @Select("select *from t_checkgroup")
    List<CheckItem> findByAllCheckGroup();

    @Insert("insert into t_checkgroup_checkitem(checkgroup_id, checkitem_id) values(#{checkGroupId},#{checkItemId})")
    void insert(CheckGroupAndCheckItem checkGroupAndCheckItem);
    @Delete("delete  from t_checkgroup_checkitem where checkgroup_id=#{checkGroupId}")
    void deleteReklation(Integer checkGroupId);

    void updateCheckGroup(CheckGroup checkGroup);
}
